<template>
  <el-dialog
    draggable
    overflow
    :title="titleMap[mode]"
    v-model="visible"
    :width="600"
    destroy-on-close
    @closed="$emit('closed')"
  >
    <!-- <sc-water-mark ref="wm" text="已审核" subtext="誉卓纱线"> -->
    <sk-tabs type="border-card">
      <el-tab-pane ref="tab" label="基础信息">
        <el-divider content-position="left">基本信息</el-divider>
        <el-form
          :model="form"
          :rules="rules"
          ref="dialogForm"
          label-width="70px"
          label-position="right"
        >
          <el-row align="bottom">
            <el-col :span="12" align="bottom">
              <el-form-item label="库存匹" prop="storage_auxiliary_quantity">
                <el-input v-model="row.storage_auxiliary_quantity" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12" align="bottom">
              <el-form-item label="库存米" prop="storage_quantity">
                <el-input v-model="row.storage_quantity" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="实际匹" prop="fect_auxiliary_quantity">
                <el-input v-model="row.fect_auxiliary_quantity" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="实际米" prop="fect_quantity">
                <el-input v-model="row.fect_quantity" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="备注" prop="remark">
                <el-input v-model="form.remark" clearable></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>
    </sk-tabs>
    <!-- </sc-water-mark> -->
    <template #footer>
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
    </template>
  </el-dialog>
</template>

<script>
import XEUtils from "xe-utils";
export default {
  emits: ["success", "closed"],
  components: {},
  data() {
    return {
      mode: "add",
      titleMap: {
        add: "新增",
        edit: "编辑",
      },

      form: {
        billdate: XEUtils.toDateString(new Date(), "yyyy-MM-dd"),
      },
      row: {},
      rules: {},
      visible: false,
      isSaveing: false,
    };
  },
  mounted() {},
  methods: {
    //显示
    open(mode = "add") {
      this.mode = mode;
      this.visible = true;
      return this;
    },
    //表单提交方法
    submit() {
      this.$refs.dialogForm.validate(async valid => {
        if (valid) {
          this.isSaveing = true;
          this.form["details"] = [this.row];
          this.form["need_audit"] = [true];
          var res = await this.$API.storage.inventory.save.post(this.form);
          this.isSaveing = false;
          if (res.code == 200) {
            this.$emit("success", this.form, this.mode);
            this.visible = false;
            this.$message.success("操作成功");
          }
        }
      });
    },
    //表单注入数据
    setData(data) {
      delete data.id;
      data["storage_auxiliary_quantity"] = parseFloat(
        data["available_auxiliary_quantity"]
      );
      data["storage_quantity"] = parseFloat(data["available_quantity"]);

      data["fect_auxiliary_quantity"] = data["storage_auxiliary_quantity"];
      data["fect_quantity"] = data["storage_quantity"];
      this.row = data;
    },
  },
};
</script>

<style></style>
